using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;

using Jamila2.CoreElements;
using Jamila2.Database;

namespace BPCSFileDaemon
{
    public class DaemonConfigurator : ManagerBase
    {
        #region Variables

        protected string archieved_path = "";
        protected string source_path = "";
        protected string logfile_path = "";
        protected string dbconn_str = "";
        protected TypeOfDatabase dbtype = TypeOfDatabase.MSSQL;
        protected bool email_active = false;
        protected string EmailSMTP = "";

        public string PathForArchievedFiles
        {
            get
            {
                return this.archieved_path;
            }
        }

        public string PathForSourceFiles
        {
            get
            {
                return this.source_path;
            }
        }

        public string PathForLogFiles
        {
            get
            {
                return this.logfile_path;
            }
        }

        public string DatabaseConnection
        {
            get
            {
                return this.dbconn_str;
            }
        }

        public string SMTP
        {
            get
            {
                return this.EmailSMTP;
            }
        }

        public TypeOfDatabase DatabaseType
        {
            get
            {
                return this.dbtype;
            }
        }

        public bool Email_Active
        {
            get
            {
                return this.email_active;
            }
        }

        #endregion

        public bool ReadConfiguration()
        {
            bool smooth = true;

            try
            {
                XmlTextReader Reader = new XmlTextReader("sysconfig.xml");

                while (Reader.Read())
                {
                    if (Reader.NodeType == XmlNodeType.Element)
                    {
                        switch (Reader.Name)
                        {
                            case "Archieved":
                                this.archieved_path = Reader.ReadString();
                                break;

                            case "Source":
                                this.source_path = Reader.ReadString();
                                break;

                            case "Log":
                                this.logfile_path = Reader.ReadString();
                                break;

                            case "DBConn":
                                this.dbconn_str = Reader.ReadString();
                                break;

                            case "EmailActive":
                                this.email_active = (Reader.ReadString().CompareTo("1") == 0);
                                break;

                            case "EmailSMTP":
                                this.EmailSMTP = Reader.ReadString();
                                break;

                            case "DBType":

                                switch (Reader.ReadString())
                                {
                                    case "MSSQL":
                                        this.dbtype = TypeOfDatabase.MSSQL;
                                        break;

                                    case "ODBC":
                                        this.dbtype = TypeOfDatabase.ODBC;
                                        break;

                                    case "OleDB":
                                        this.dbtype = TypeOfDatabase.OleDB;
                                        break;
                                }

                                break;


                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.ErrMsg = "[DaemonConfigurator.ReadConfiguration] : Exception : " + ex.Message;
            }

            return smooth;

        }

    }
}
